/*---------------------------------------------------------------------------/
/  Configurations of FatFs Module
/---------------------------------------------------------------------------*/

#define FFCONF_DEF	80286	/* Revision ID */

/**
 *  编码体系：
 *      1、Unicode是一种全球字符编码标准，为世界上所有文字和符号提供一个统一
 *         的编码，它仅规定了符号的编码，并未规定编码的传输与存储方式;
 *      2、Unicode包含三种编码方案：UTF-8、UTF-16、UTF-32，这三种编码方式通过
 *         移位操作可以很容易进行转换;
 *           1、UTF-8使用1到4个字节表示每个字符，具有很好的兼容性和灵活性，
 *              使用最广;
 *           2、UTF-16使用2到4个字节表示每个字符，是许多现代操作系统和程序环
 *              境的内部编码方式，如Java、Windows;
 *           3、UTF-32每个字符固定使用4个字节，简化了数据处理，但体积大很多;
 *      3、GB232于1980年发布，采用双字节表示一个字符，高字节为区码(0xA1-0xF7)，
 *         低字节为位码(0xA1-0xFE)，包含3755个一级汉字、3008个二级汉字以及682
 *         个符号，符号包括拉丁字母、希腊字母、日文假名等字符;
 *      4、GBK在GB2312上进行了扩展，支持了繁体字、俄文等多语言，GB18030又在
 *         GBK进行的扩展，支持少数民族的文字符号，GB18030是我国目前法定的字符
 *         编码标准，由于GB18030中有许多字符极少使用，所以主流设备中GBK使用
 *         居多;
 *      5、ASCII、GB2312、GBK、GB18030这些编码是向下兼容的，后三者均采用双字
 *         节编码，大端模式;
 *      6、ANSI不是一种特定编码，在不同系统中表示不同编码，在中文系统中对应为
 *         GBK(CP936);
 *      7、目前windows内核采用Unicode编码，为了处理各国自己语言编码，设计了
 *         CodePage概念，GB2312对应CP20936，GBK对应CP936，GB18030对应CP54936，
 *         通过切换不同的代码页，Windows即可处理不同国家自己的编码;
 *      8、Unicode和ASCII兼容但和GBK不兼容，两者需要通过查表进行转换，故需要
 *         两个86KB左右的表格来实现双向转换，如有需要可考虑将转换表保存到其他
 *         存储器中，或者保存在Fat文件系统中，但必须是英文路径;
 *      9、对于文件系统，目录名和文件名与编码有关，需要设置正确的编码才能正确
 *         的查找到文件，windows默认采用GBK编码，其在FAT磁盘上创建的目录或文件
 *         名，均是GBK格式，尽管windows可以将文件另存为UTF8格式，但也仅影响了
 *         文本内容，文件名还是GBK格式。
 *      10、windows也可以是在【设置】》【时间和语言】》【语言】》【管理语言
 *         设置】》【更改系统区域设置】》【勾选使用UTF8提供全球语言支持】，
 *         重启系统后，磁盘中所有文件名将被转换为UTF8格式，并且之后创建的文
 *         件名也会是UTF8格式。Linux系统下可以使用"convmv -f GB2312 -t UTF-8
 *         -r --notest"命令将磁盘中的文件名修改为UTF-8格式。
 *      11、Fatfs的路径采用Unicode格式，而通常windows在磁盘中创建的文件名是
 *         CP936，故在打开中文路径时，会调用ff_uni2oem()，
 */

/*---------------------------------------------------------------------------/
/ Function Configurations
/---------------------------------------------------------------------------*/

#define FF_FS_READONLY	0
/* This option switches read-only configuration. (0:Read/Write or 1:Read-only)
/  Read-only configuration removes writing API functions, f_write(), f_sync(),
/  f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree()
/  and optional writing functions as well. */


#define FF_FS_MINIMIZE	2
/* This option defines minimization level to remove some basic API functions.
/
/   0: Basic functions are fully enabled.
/   1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename()
/      are removed.
/   2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.
/   3: f_lseek() function is removed in addition to 2. */


/**
 * 2表示使能匹配备选文件名(Alternative file name)，也即8.3格式的短文件名，
 * 使能长文件名后仍然会存在一个短文件名，当长文件名匹配不成功时，匹配短文件名
 */
#define FF_USE_FIND		0
/* This option switches filtered directory read functions, f_findfirst() and
/  f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */


#define FF_USE_MKFS		1
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */


/**
 * DWORD clmt[SZ_TLB]; // 任意大小
 * clmt[0] = SZ_TLB;   // 大小赋值给元素0
 * fp->cltbl = clmt;   // 需手动赋值
 * f_lseek(fp, CREAT_LINKMAP); // 将文件的簇信息保存到clmt中，之后f_lseek()
 * 可以直接在该数组中查询簇信息，不需要再读取SD中的Fat表了，对于需要随机读
 * 写文件（频繁使用f_lseek函数修改文件指针）有帮助。当然即使使能了该特性，但
 * 没有执行f_lseek(fp, CREAT_LINKMAP)这一步，f_lseek仍会采用原先Fat表的方式
 * 进行。
 */
#define FF_USE_FASTSEEK	1
/* This option switches fast seek function. (0:Disable or 1:Enable) */


/**
 * 在磁盘上查找一个大小的连续空间，创建一个新文件，新文件的内容
 * 是随机值，关闭文件后可以绕开文件系统，使用底层驱动直接读写该文件，虽然不
 * 推荐这样做。另外当文件的扇区连续时，数据的访问也要更快一些，需注意，
 * f_expand只能创建新文件或扩展文件大小为0的文件，该文件使用f_write写入后可
 * 能就不连续了，文件体积减小或不变时，FatFs本身不会更换簇的位置，仍然是连续
 * 的，不知道其他Fat系统是否也是这样，理论上这样做可以减少Fat表的修改次数，
 * 但就是不支持擦写均衡了，SD内部自带擦写均衡，也不需要上层做管理，其他裸存
 * 储，比如SPI Flash则需要在diskio.c层做擦写均衡。官方文档中提供了检测文件
 * 扇区是否连续的方法。
 */
#define FF_USE_EXPAND	1
/* This option switches f_expand function. (0:Disable or 1:Enable) */


#define FF_USE_CHMOD	0
/* This option switches attribute manipulation functions, f_chmod() and f_utime().
/  (0:Disable or 1:Enable) Also FF_FS_READONLY needs to be 0 to enable this option. */

/**
 * 类似于Windows上的磁盘名
 */
#define FF_USE_LABEL	0
/* This option switches volume label functions, f_getlabel() and f_setlabel().
/  (0:Disable or 1:Enable) */

/**
 * 支持将文件内容直接读取到其它数据流，这样可减少一次拷贝
 */
#define FF_USE_FORWARD	0
/* This option switches f_forward() function. (0:Disable or 1:Enable) */


#define FF_USE_STRFUNC	0
#define FF_PRINT_LLI	1
#define FF_PRINT_FLOAT	1
#define FF_STRF_ENCODE	3
/* FF_USE_STRFUNC switches string functions, f_gets(), f_putc(), f_puts() and
/  f_printf().
/
/   0: Disable. FF_PRINT_LLI, FF_PRINT_FLOAT and FF_STRF_ENCODE have no effect.
/   1: Enable without LF-CRLF conversion.
/   2: Enable with LF-CRLF conversioni，使能\r\n的转换.
/
/  FF_PRINT_LLI = 1 makes f_printf() support long long argument and FF_PRINT_FLOAT = 1/2
/  makes f_printf() support floating point argument. These features want C99 or later.
/  When FF_LFN_UNICODE >= 1 with LFN enabled, string functions convert the character
/  encoding in it. FF_STRF_ENCODE selects assumption of character encoding ON THE FILE
/  to be read/written via those functions.
/
/  设置磁盘上文件内容的编码格式
/   0: ANSI/OEM in current CP
/   1: Unicode in UTF-16LE，小端
/   2: Unicode in UTF-16BE，大端
/   3: Unicode in UTF-8
*/


/*---------------------------------------------------------------------------/
/ Locale and Namespace Configurations
/---------------------------------------------------------------------------*/

#define FF_CODE_PAGE	437
/* This option specifies the OEM code page to be used on the target system.
/  Incorrect code page setting can cause a file open failure.
/  设置SD卡文件系统中目录/文件名的编码格式
/
/   437 - U.S.美国
/   720 - Arabic阿拉伯
/   737 - Greek希腊
/   771 - KBL
/   775 - Baltic波罗的海
/   850 - Latin 1拉丁语1
/   852 - Latin 2拉丁语2
/   855 - Cyrillic西里尔
/   857 - Turkish土耳其
/   860 - Portuguese葡萄牙
/   861 - Icelandic冰岛
/   862 - Hebrew希伯来
/   863 - Canadian French加拿大法语
/   864 - Arabic阿拉伯
/   865 - Nordic北欧
/   866 - Russian俄语
/   869 - Greek 2希腊2
/   932 - Japanese (DBCS)日本（Double-Byte Character Set，双字节字符集）
/   936 - Simplified Chinese (DBCS)简体中文（双字节字符集）,用于GB2312与Unicode之间的转换
/   949 - Korean (DBCS)韩语（双字节字符集）
/   950 - Traditional Chinese (DBCS)繁体中文（双字节字符集）
/     0 - Include all code pages above and configured by f_setcp()
*/


/**
 * 使能长文件名并放在堆上时，需要实现内存管理函数，此时f_fdisk和f_mkfs的work
 * 参数可以为NULL，函数内部会进行内存申请。
 */
#define FF_USE_LFN		3
#define FF_MAX_LFN		255
/* The FF_USE_LFN switches the support for LFN (long file name).
/
/   0: Disable LFN. FF_MAX_LFN has no effect.
/   1: Enable LFN with static  working buffer on the BSS. Always NOT thread-safe.
/   2: Enable LFN with dynamic working buffer on the STACK.
/   3: Enable LFN with dynamic working buffer on the HEAP.
/
/  To enable the LFN, ffunicode.c needs to be added to the project. The LFN function
/  requiers certain internal working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and
/  additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled.
/  The FF_MAX_LFN defines size of the working buffer in UTF-16 code unit and it can
/  be in range of 12 to 255. It is recommended to be set it 255 to fully support LFN
/  specification.
/  When use stack for the working buffer, take care on stack overflow. When use heap
/  memory for the working buffer, memory management functions, ff_memalloc() and
/  ff_memfree() exemplified in ffsystem.c, need to be added to the project. */


/**
 * 设置Fatfs API的编码格式，也即影响了TCHAR的类型，当设置为0时，虽然API接口和
 * 磁盘的数据编码是一致的，但是Fatfs中统一使用UTF-16进行文件名的创建和查询，故
 * 会涉及到ff_oem2uni()
 */
#define FF_LFN_UNICODE	2
/* This option switches the character encoding on the API when LFN is enabled.
/
/   0: ANSI/OEM in current CP (TCHAR = char)
/   1: Unicode in UTF-16 (TCHAR = WCHAR)
/   2: Unicode in UTF-8 (TCHAR = char)
/   3: Unicode in UTF-32 (TCHAR = DWORD)
/
/  Also behavior of string I/O functions will be affected by this option.
/  When LFN is not enabled, this option has no effect. */


/**
 * SFN(Short File Name)，短文件名，8.3格式的文件名
 */
#define FF_LFN_BUF		255
#define FF_SFN_BUF		12
/* This set of options defines size of file name members in the FILINFO structure
/  which is used to read out directory items. These values should be suffcient for
/  the file names to read. The maximum possible length of the read file name depends
/  on character encoding. When LFN is not enabled, these options have no effect. */

/**
 * 配置为0时，FatFs仅支持绝对路径，下表中x表示当前磁盘或当前文件夹
 * +-------------+-------------+---------------+
 * | 文件名      |   RPATH=0   |    RPATH>0    |
 * +-------------+-------------+---------------+
 * | file.txt    | 0:/file.txt | ./file.txt    |
 * | /file.txt   | 0:/file.txt | x:/file.txt   |
 * |             | 0:/         | x:/x/         |
 * | /           | 0:/         | x:/           |
 * | 2:          | 2:/         | 2:/x/         |
 * | 2:/         | 2:/         | 2:/           |
 * | 2:file.txt  | 2:/file.txt | 2:/x/file.txt |
 * | ../file.txt | 非法        | ../file.txt   |
 * | .           | 非法        | ./            |
 * | ..          | 非法        | ../           |
 * | dir/..      | 非法        | ./            |
 * | /..         | 非法        | /             |
 * +-------------+-------------+---------------+
 */
#define FF_FS_RPATH		2
/* This option configures support for relative path.
/
/   0: Disable relative path and remove related functions.
/   1: Enable relative path. f_chdir() and f_chdrive() are available.
/   2: f_getcwd() function is available in addition to 1.
*/


/*---------------------------------------------------------------------------/
/ Drive/Volume Configurations
/---------------------------------------------------------------------------*/

/**
 * 最大支持的逻辑磁盘的数量，一个物理磁盘可以有多个分区，即等同于多个逻辑
 * 磁盘，因为盘符只能为"0:"到"9:"，故最大仅支持10个逻辑磁盘
 */
#define FF_VOLUMES		1
/* Number of volumes (logical drives) to be used. (1-10) */

/**
 * 0: 可以使用0:/file.txt的方式访问文件
 * 1: 可以使用0:/file.txt或ram:/file.txt的方式访问文件
 * 2: 可以使用0:/file.txt或/ram/file.txt的方式访问文件
 */
#define FF_STR_VOLUME_ID	0
#define FF_VOLUME_STRS		"RAM","NAND","CF","SD","SD2","USB","USB2","USB3"
/* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings.
/  When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive
/  number in the path name. FF_VOLUME_STRS defines the volume ID strings for each
/  logical drives. Number of items must not be less than FF_VOLUMES. Valid
/  characters for the volume ID strings are A-Z, a-z and 0-9, however, they are
/  compared in case-insensitive. If FF_STR_VOLUME_ID >= 1 and FF_VOLUME_STRS is
/  not defined, a user defined volume string table is needed as:
/
/  const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",...
*/

/**
 * 一个物理磁盘可以包含多个逻辑分区，每个逻辑分区即可作为一个逻辑磁盘，用户需
 * 要定义VolToPart这个变量，这个变量描述了，逻辑分区编号（文件挂载和文件路径）
 * 和物理磁盘（disk_操作）编号的映射关系，若f_mkfs想要将磁盘格式化为多个分区，
 * 也需要定义该变量，并在该变量中描述要分区的数量
 */
#define FF_MULTI_PARTITION	0
/* This option switches support for multiple volumes on the physical drive.
/  By default (0), each logical drive number is bound to the same physical drive
/  number and only an FAT volume found on the physical drive will be mounted.
/  When this function is enabled (1), each logical drive number can be bound to
/  arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk()
/  function will be available. */


/**
 * 影响文件系统格式化、分区和挂载。通常磁盘扇区为512，但如果还有其他磁盘，
 * 比如SPI Flash等，则扇区可能比较大，此时需要实现disk_ioctl中
 * GET_SECTOR_SIZE命令
 */
#define FF_MIN_SS		512
#define FF_MAX_SS		512
/* This set of options configures the range of sector size to be supported. (512,
/  1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and
/  harddisk, but a larger value may be required for on-board flash memory and some
/  type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured
/  for variable sector size mode and disk_ioctl() function needs to implement
/  GET_SECTOR_SIZE command. */


#define FF_LBA64		0
/* This option switches support for 64-bit LBA. (0:Disable or 1:Enable)
/  To enable the 64-bit LBA, also exFAT needs to be enabled. (FF_FS_EXFAT == 1) */


/**
 * MBR和GPT格式的临界点
 */
#define FF_MIN_GPT		0x10000000
/* Minimum number of sectors to switch GPT as partitioning format in f_mkfs and
/  f_fdisk function. 0x100000000 max. This option has no effect when FF_LBA64 == 0. */


/**
 * ATA设备中会使用
 */
#define FF_USE_TRIM		0
/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable)
/  To enable Trim function, also CTRL_TRIM command should be implemented to the
/  disk_ioctl() function. */



/*---------------------------------------------------------------------------/
/ System Configurations
/---------------------------------------------------------------------------*/

/**
 * Tiny模式下，FIL中的文件读写buf将被移除，结构体减少FF_MAX_SS字节，此时文件
 * 读写将使用FATFS中公共的buf，在多个文件读写的过程中会有较大的开销。
 */
#define FF_FS_TINY		0
/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)
/  At the tiny configuration, size of file object (FIL) is shrinked FF_MAX_SS bytes.
/  Instead of private sector buffer eliminated from the file object, common sector
/  buffer in the filesystem object (FATFS) is used for the file data transfer. */


#define FF_FS_EXFAT		0
/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable)
/  To enable exFAT, also LFN needs to be enabled. (FF_USE_LFN >= 1)
/  Note that enabling exFAT discards ANSI C (C89) compatibility. */


/**
 * 设置为1可关闭文件系统的时间标签功能，所有的文件操作都将使用下面的宏时间替
 * 代，Fat文件系统使用U32存储时间戳
 *   [31:25]: 7bits，年，1980到2107
 *   [24:21]: 4bits，月，1到12
 *   [20:16]: 5bits，日，1到31
 *   [15:11]: 5bits，时，0到23
 *   [10: 5]: 6bits，分，0到59
 *   [ 4: 0]: 5bits，秒，0到29，以两秒间隔计数
 */
#define FF_FS_NORTC		1
#define FF_NORTC_MON	1
#define FF_NORTC_MDAY	1
#define FF_NORTC_YEAR	2022
/* The option FF_FS_NORTC switches timestamp feature. If the system does not have
/  an RTC or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable the
/  timestamp feature. Every object modified by FatFs will have a fixed timestamp
/  defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time.
/  To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be
/  added to the project to read current time form real-time clock. FF_NORTC_MON,
/  FF_NORTC_MDAY and FF_NORTC_YEAR have no effect.
/  These options have no effect in read-only configuration (FF_FS_READONLY = 1). */


/**
 * 如果定义为3的话，FATFS中的last_clst和free_clst会被赋值为0xFFFFFFFF，反之
 * 程序会在挂载磁盘的时候计算真实的值
 */
#define FF_FS_NOFSINFO	0
/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
/  option, and f_getfree() function at the first time after volume mount will force
/  a full FAT scan. Bit 1 controls the use of last allocated cluster number.
/
/  bit0=0: Use free cluster count in the FSINFO if available.
/  bit0=1: Do not trust free cluster count in the FSINFO.
/  bit1=0: Use last allocated cluster number in the FSINFO if available.
/  bit1=1: Do not trust last allocated cluster number in the FSINFO.
*/


/**
 * 只读文件系统时该值应设置为0，可读写的文件系统，该值会影响文件系统能同时
 * 打开的文件/子目录数量，因为每个文件都需要一个互斥信号量以实现可重入。定义
 * 为0时，需要编程者自己注意不要非法打开、移除和重命名一个已打开的文件。定义
 * 为1时，上述非法操作会返回ERROR，FS_LOCK本身是不可重入的，多线程使用时仍需
 * 要开启FF_FS_REENTRANT。
 */
#define FF_FS_LOCK		10
/* The option FF_FS_LOCK switches file lock function to control duplicated file open
/  and illegal operation to open objects. This option must be 0 when FF_FS_READONLY
/  is 1.
/
/  0:  Disable file lock function. To avoid volume corruption, application program
/      should avoid illegal open, remove and rename to the open objects.
/  >0: Enable file lock function. The value defines how many files/sub-directories
/      can be opened simultaneously under file lock control. Note that the file
/      lock control is independent of re-entrancy. */


/**
 * 可重入，访问不同卷上的文件/目录总是可重入的，f_mount/f_mkfs/f_fdisk以及
 * 访问同一个卷的不同文件，总是不可重入的，因为同一个卷公用同一个
 * FATFS *FatFs[FF_VOLUMES]结构体，读写不同文件会修改该结构体数据。
 */
#define FF_FS_REENTRANT	0
#define FF_FS_TIMEOUT	1000
/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
/  module itself. Note that regardless of this option, file access to different
/  volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
/  and f_fdisk() function, are always not re-entrant. Only file/directory access
/  to the same volume is under control of this featuer.
/
/   0: Disable re-entrancy. FF_FS_TIMEOUT have no effect.
/   1: Enable re-entrancy. Also user provided synchronization handlers,
/      ff_mutex_create(), ff_mutex_delete(), ff_mutex_take() and ff_mutex_give()
/      function, must be added to the project. Samples are available in ffsystem.c.
/
/  The FF_FS_TIMEOUT defines timeout period in unit of O/S time tick.
*/



/*--- End of configuration options ---*/
